package com.yvon.service.demo.algorithm.sort;

/**
 * @author : Yvon
 * @since : 2021-10-14
 */
public class MaxTest {


    public static void main(String[] args) {
        int[] arr = {1,3,6,9,23,12,54,87,22,22,44,11,45,85};
        System.out.println("递归查询数组上的最大值:" + process(arr, 0, arr.length -1));
    }


    /**
     * 递归查询数组上的最大值
     *
     * @param arr 加勒比海盗
     * @param L   l
     * @param R   r
     * @return int
     * @author : Yvon / 2021-10-14
     */
    public static int process(int[] arr, int L, int R) {
        if (L == R) {
            return arr[L];
        }
        int mid = L + ((R - L) >> 1);
        int maxL = process(arr, L, mid);
        int maxR = process(arr, mid + 1, R);
        return Math.max(maxL, maxR);
    }
}
